package com.mzj.saas.mservice.smartlock.controller;

import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.smartlock.service.xizhao.SmartLockXzService;
import com.mzj.saas.mservice.smartlock.vo.DevMacStateVO;
import com.mzj.saas.mservice.smartlock.vo.DynamicPasswordVO;
import com.mzj.saas.mservice.smartlock.vo.SmartLockFingerprintVO;
import com.mzj.saas.mservice.smartlock.vo.SmartLockVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 测试智能锁接口
 */
@Controller
@RequestMapping("device/lock/xz")
public class SmartLockTest2Controller {

	@Autowired
	private SmartLockXzService smartLockApiService;

	/**
	 * 注册设备事件消息推送地址
	 * 
	 * @param accessToken
	 * @param brandId
	 * @return
	 * @author shun
	 * @date 2021年6月26日
	 */
	@PostMapping("/register")
	@ResponseBody
	public ResultBean<String> callBackRegister(@RequestHeader String accessToken, @RequestParam Long brandId) {
		return smartLockApiService.callBackRegister(brandId);
	}

	/**
	 * 注册NB新设备
	 * 
	 * @param accessToken
	 * @param imei
	 * @param brandId
	 * @return
	 * @author shun
	 * @date 2021年6月28日
	 */
	@PostMapping("/bindimei")
	@ResponseBody
	public ResultBean<String> bindimei(@RequestHeader String accessToken, @RequestParam String imei,
			@RequestParam Long brandId) {
		return smartLockApiService.bindimei(imei, "智能锁", brandId);
	}

	/**
	 * 获取设备状态
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@GetMapping("/getState")
	@ResponseBody
	public ResultBean<DevMacStateVO> getState(@RequestHeader String accessToken, @RequestParam String sn,
			@RequestParam Long brandId) {
		return smartLockApiService.getState(sn, brandId);
	}

	/**
	 * 查询动态密码
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@GetMapping("/dynamicPassword")
	@ResponseBody
	ResultBean<List<DynamicPasswordVO>> getDynamicPassword(@RequestHeader String accessToken, @RequestParam String sn,
			@RequestParam Long brandId) {
		return smartLockApiService.getDynamicPassword(sn, brandId);
	}

	/**
	 * 新增密码
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/operationPassword")
	@ResponseBody
	public ResultBean<String> operationPassword(@RequestHeader String accessToken, @RequestBody SmartLockVO vo,
			@RequestParam Long brandId) {
		return smartLockApiService.operationPassword(vo, brandId);
	}

	/**
	 * 修改密码
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/updatePassword")
	@ResponseBody
	public ResultBean<String> updatePassword(@RequestHeader String accessToken, @RequestBody SmartLockVO vo,
			@RequestParam Long brandId) {
		return smartLockApiService.updatePassword(vo, brandId);
	}

	/**
	 * 修改密码有效期
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/updatePasswordTime")
	@ResponseBody
	public ResultBean<String> updatePasswordTime(@RequestHeader String accessToken, @RequestBody SmartLockVO vo,
			@RequestParam Long brandId) {
		return smartLockApiService.updatePasswordTime(vo, brandId);
	}

	/**
	 * 冻结/解冻密码
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/freezeOrUnfreeze")
	@ResponseBody
	public ResultBean<String> freezeOrUnfreeze(@RequestHeader String accessToken, @RequestBody SmartLockVO vo,
			@RequestParam Long brandId, @RequestParam Integer operatorType) {
		return smartLockApiService.freezeOrUnfreeze(vo, brandId, operatorType);
	}

	/**
	 * 删除密码
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/clearPassword")
	@ResponseBody
	public ResultBean<String> clearPassword(@RequestHeader String accessToken, @RequestBody SmartLockVO vo,
			@RequestParam Long brandId, @RequestParam String operatorType) {
		return smartLockApiService.clearPassword(vo, brandId, operatorType);
	}

	/**
	 * 新增卡
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/operationCardPassword")
	@ResponseBody
	public ResultBean<String> operationCardPassword(@RequestHeader String accessToken, @RequestBody SmartLockVO vo,
			@RequestParam Long brandId) {
		return smartLockApiService.operationCardPassword(vo, brandId);
	}

	/**
	 * 修改卡
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/updateCard")
	@ResponseBody
	public ResultBean<String> updateCard(@RequestHeader String accessToken, @RequestBody SmartLockVO vo,
			@RequestParam Long brandId) {
		return smartLockApiService.updateCard(vo, brandId);
	}

	/**
	 * 修改卡片有效期
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/updateCardTime")
	@ResponseBody
	public ResultBean<String> updateCardTime(@RequestHeader String accessToken, @RequestBody SmartLockVO vo,
			@RequestParam Long brandId) {
		return smartLockApiService.updateCardTime(vo, brandId);
	}

	/**
	 * 新增指纹
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/addFingerprint")
	@ResponseBody
	public ResultBean<String> addFingerprint(@RequestHeader String accessToken, @RequestBody SmartLockFingerprintVO vo,
			@RequestParam Long brandId) {
		return smartLockApiService.addFingerprint(vo, brandId);
	}

	/**
	 * 修改指纹
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/updateFingerprint")
	@ResponseBody
	public ResultBean<String> updateFingerprint(@RequestHeader String accessToken,
			@RequestBody SmartLockFingerprintVO vo, @RequestParam Long brandId) {
		return smartLockApiService.updateFingerprint(vo, brandId);
	}

	/**
	 * 修改指纹有效期
	 * 
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/updateFingerprintTime")
	@ResponseBody
	public ResultBean<String> updateFingerprintTime(@RequestHeader String accessToken,
			@RequestBody SmartLockFingerprintVO vo, @RequestParam Long brandId) {
		return smartLockApiService.updateFingerprintTime(vo, brandId);
	}
}
